<?php
class ModelAccountReview extends Model {
	
	/**
	 * 获取当前登陆用户所有评论总数
	 */
	function getTotalReviews() {
		$query = $this->db->query ( "SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "review` WHERE customer_id = " . ( int ) $this->customer->getId () );
		
		return $query->row ['total'];
	}
	
	/**
	 * 获取当前登陆用户评论详情
	 * @param unknown_type $page
	 * @param unknown_type $size
	 */
	function getReviews($page, $size) {
		$query = $this->db->query ( "SELECT r.*,i.image,p.name 
									 FROM `" . DB_PREFIX . "review` r 
									 JOIN `" . DB_PREFIX . "product_image` i 
									 JOIN `" . DB_PREFIX . "product_description` p 
									 WHERE r.product_id=i.product_id AND r.product_id=p.product_id AND r.customer_id = " . ( int ) $this->customer->getId ()  . " GROUP BY r.product_id LIMIT {$page},{$size}");
		
		return $query->rows;
	}
}